package com.uchiha.nova.mainService.wrapper;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.uchiha.nova.core.model.entity.MachineGroupEntity;
import com.uchiha.nova.core.model.vo.MachineGroupVO;
import com.uchiha.nova.core.tool.support.BaseEntityWrapper;
import com.uchiha.nova.core.tool.util.SpringUtil;
import com.uchiha.nova.mainService.service.IMachineGroupService;

import java.util.List;
import java.util.stream.Collectors;
/**
 * 机器设备分组 包装类,返回视图层所需的字段
 *
 * @author Uchihashiamu
 */
public class MachineGroupWrapper extends BaseEntityWrapper<MachineGroupEntity, MachineGroupVO>  {
  
  IMachineGroupService machineGroupService = SpringUtil.getBean(IMachineGroupService.class);
  
	public static MachineGroupWrapper build() {
		return new MachineGroupWrapper();
 	}

	@Override
	public MachineGroupVO entityVO(MachineGroupEntity machineGroupEntity) {
		MachineGroupVO machineGroupVO = new MachineGroupVO();
		BeanUtil.copyProperties(machineGroupEntity, machineGroupVO);

		return machineGroupVO;
	}
	public List<MachineGroupVO> listVO(List<MachineGroupEntity> list) {
		List<MachineGroupVO> collect = list.stream().map(item -> {
            MachineGroupVO machineGroupVO = new MachineGroupVO();
		    BeanUtil.copyProperties(item, machineGroupVO);			
			return machineGroupVO;
		}).collect(Collectors.toList());
		return collect;
    // return ForestNodeMerger.merge(collect);
	}
  
  	@Override
	public IPage<MachineGroupVO> pageVO(IPage<MachineGroupEntity> pages) {
		IPage<MachineGroupVO> page = pages.convert(item->{
            MachineGroupVO machineGroupVO = new MachineGroupVO();
		    BeanUtil.copyProperties(item, machineGroupVO);			
			return machineGroupVO;
		});
		return page;
	}
}
